package cn.tedu;

/**
 * @author liyuehui
 * @time 2024/7/30 17:42
 */
public class RectangeArea {
    public int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {
        // int simpleSum = (ax2 - ax1) * (ay2 - ay1) + (bx2 - bx1) * (by2 - by1);
        // int publicArea = Math.max(0, Math.min(ax2, bx2) - Math.max(ax1, bx1)) * Math.max(0, Math.min(ay2, by2) - Math.max(ay1, by1));
        return (ax2 - ax1) * (ay2 - ay1) + (bx2 - bx1) * (by2 - by1)- Math.max(0, Math.min(ax2, bx2) - Math.max(ax1, bx1)) * Math.max(0, Math.min(ay2, by2) - Math.max(ay1, by1));
    }
    public static void main(String[] args) {
        RectangeArea ra = new RectangeArea();
        int area1 = ra.computeArea(-3, 0, 3, 4, 0, -1, 9, 2);
        System.out.println(area1);
        int area2 = ra.computeArea(-2, -2, 2, 2, -2, -2, 2, 2);
        System.out.println(area2);
    }
}
